<template>
	<view>
		<convenientPublish :beforeInfo="dataInfo" :articleCategoryID="articleCategoryID" v-if="status == 1" />

		<articlePublish :beforeInfo="dataInfo" :articleCategoryID="articleCategoryID" v-if="status == 2" />

		<officialPublish :beforeInfo="dataInfo" :articleCategoryID="articleCategoryID" v-if="status == 3" />
	</view>
</template>

<script>
	import { GetArticleDetail } from "@/API/article.js";
	import convenientPublish from "@/components/publish/convenientPublish.vue";
	import officialPublish from "@/components/publish/officialPublish.vue";
	import articlePublish from "@/components/publish/articlePublish.vue";
	export default {
		components: {
			convenientPublish,
			officialPublish,
			articlePublish,
		},
		data() {
			return {
				status: 0, //1:便民信息发布 2:头条类发布 3:官方账号发布
				articleCategoryID: "", //文章分类ID

				dataInfo: null, //文章详情数据
				articleID: "", //文章ID
			};
		},
		onLoad(options) {
			if (options.status) {
				this.status = options.status;
				this.articleCategoryID = options.article_category_id;
				
				uni.setNavigationBarTitle({
					title: "发布"
				})
			}

			if (options.id) {
				this.articleID = options.id;
				
				uni.setNavigationBarTitle({
					title: "修改"
				})
				
				this.getData();
			}
		},
		methods: {
			/**
			 * 获取之前的信息
			 */
			getData() {
				GetArticleDetail(this.articleID).then((res) => {
					this.dataInfo = res.data;
					this.articleCategoryID = res.data.article_category_id;
					
					if (res.data.type === "1") {
						this.status = 2;
					} else if (res.data.type === "2") {
						this.status = 1;
					} else if (res.data.type === "3") {
						this.status = 3;
					}
				});
			},
		},
	};
</script>
